package com.ivr.cm.handler;

import com.ivr.cm.data.BaseData;
import com.ivr.cm.service.BaseServiceIF;
import com.ivr.cm.util.SpringServiceUtil;


/**
 * 具体的需要继承BaseHandler并实现action方法，并返回处理结果(responsebody)
 * 子类可选择性的实现initialize
 * 子类不需要关心vspp的接收、解包、发送
 * 方便以后进行移植，比如改为http方式接收
 * @author liugeng
 * @date 2015-12-15
 *
 */
public abstract class BaseHandler {
	
	protected void initialize(){
		
	}
	public String doAction(BaseData baseData) {
		/**实现具体方法前执行的函数*/
		beforeAction(baseData);
		/**开始执行action函数*/
		String responseBody = action(baseData);
		/**执行action函数后执行的函数*/
		afterAction(baseData);
		
		return responseBody;
	}
	/*
	 * 在此方法里边执行所有handler都会用到的公用代码
	 */
	@SuppressWarnings({ "unchecked", "rawtypes" })
	protected void beforeAction(BaseData baseData){
		/**补充主叫号码的省市*/
		BaseServiceIF addAreaServiceImpl = (BaseServiceIF)SpringServiceUtil.getService("addAreaServiceImpl");
		addAreaServiceImpl.doProcess(baseData);
		/**是否需要扣量*/
	}
	
	protected abstract String action(BaseData baseData);
	
	protected void afterAction(BaseData baseData){
		
	}
}